package com.stu.day02;

/**
 * 字符串的不可变性
 * @author zy
 * @date 2025/1/23 20:30
 */
public class StringDemo {
    public static void main(String[] args) {
//        String str = "dog";
        String str = new String("dog");
        char[] chars = {'a', 'a', 'a'};

        System.out.println("字符串: "+str+"\t字符数组: "+new String(chars));
        new StringDemo().test(str,chars);
        System.out.println("字符串: "+str+"\t字符数组: "+new String(chars));  //字符串是不可变的
    }
    void test(String str,char[] arr) {
        str = "cat";
        arr[0] = 'b';
    }
}
